<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Site
 *
 * @author DENY PRASETIA TW
 */
class Site extends CI_Controller {
    
    #Variabel untuk menghandel data yang diparsing kedalam file home.php
    #status : ok
    private $template;

    #Function konstruktor
    #status : ok
    function __construct() {
        parent::__construct();
        $this->load->model(array('Pegawai'));
    }
    
    #Function index
    #status : ok
    function index() {
        $this->menu('');
    }
        
    #Function untuk memilih menu dan dilakukan parsing kedalam file home.php
    #status : ok
    function menu($input) {
        $this->load->library('Pagination');
        switch ($input) {
            case "Manajemen_user":
                /*Seting pagination*/
                $config['base_url']     = base_url().'index.php/Site/menu/Manajemen_user/';
                if($this->input->post('i_nama_pegawai') == NULL){
                    $config['total_rows']   = $this->Pegawai->count_all();
                }else{
                    $config['total_rows']   = $this->Pegawai->count_search($this->input->post('i_nama_pegawai'));
                }                
                $config['per_page']     = 20;
                $config['next_link']    = 'Before';
                $config['prev_link']    = 'After';
                $config['uri_segment']  = 4;
                $this->pagination->initialize($config);

                /*Seting input*/
                $input_pagination = array(
                    'limit'         => $config['per_page'],
                    'start'         => $this->uri->segment(4),
                    'nama_pegawai'  => $this->input->post('i_nama_pegawai')
                );
                
                /*Seting input*/
                $this->template['daftar_pegawai']   = $this->Pegawai->search($input_pagination);
                $this->template["links"]            = $this->pagination->create_links();
                
                /*Melakukan load terhadap view*/
                $this->template['dynamic_content'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Manajemen_klasifikasi":
                $this->template['dynamic_content'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Manajemen_arsip":
                $this->template['dynamic_content'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Manajemen_report":
                $this->template['dynamic_content'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Form_registrasi":
                $this->template['dynamic_content'] = $input;
                $this->load->view('Home', $this->template);
                break;
            case "Form_editpegawai":
                $this->template['dynamic_content'] = $input;
                $this->load->view('Home', $this->template);
                break;
            default:
                if($this->session->userdata('s_hak_akses') != NULL){
                    $this->template['dynamic_content'] = 'Welcome_message';
                }else{
                    $this->template['dynamic_content'] = 'Form_login';
                }
                $this->load->view('Home', $this->template);
                break;
        }
    }
            
    function valid_arsipkan_file() {
        
    }

    function valid_cari_arsip() {
        
    }
    
        
    #Function untuk menangani registrasi pegawai
    #status : ok
    function validasi_registrasi_pegawai(){
        $input = array(
            'id_pegawai'    => $this->input->post('i_id_pegawai'),
            'nama_pegawai'  => $this->input->post('i_nama_pegawai'),
            'password'      => $this->input->post('i_password'),
            'hak_akses'     => $this->input->post('i_hak_akses')
        );
        
        $this->form_validation->set_rules('i_id_pegawai', 'No Induk', 'required|min_length[5]|max_length[18]|integer');
        $this->form_validation->set_rules('i_nama_pegawai', 'Nama Lengkap', 'required|min_length[6]|max_length[25]');
        $this->form_validation->set_rules('i_password', 'Password', 'required|min_length[8]|max_length[15]');
        $this->form_validation->set_rules('i_hak_akses', 'Jabatan', 'required');
        
        if($this->form_validation->run() == FALSE){
            $this->menu('Form_registrasi');
        }else{
            $this->Pegawai->insert($input);
            $this->menu('Form_registrasi');
        }
    }

        
    #Function untuk menangani edit data pegawai
    #status : ok
    function validasi_edit_pegawai($id) {
        if($id != NULL){
            $input['id_pegawai'] = $id;
            $this->template['data_pegawai'] = $this->Pegawai->detail($input);
            $this->menu('Form_editpegawai');
        }else{
            echo show_error("Silahkan seleksi yang akan diubah terlebih dahulu");
        }
    }

        
    #Function untuk menyimpan perubahan terhadap data pegawai
    #status : ok
    function validasi_simpan_perubahan_pegawai() {
        $input = array(
            'id_pegawai'     => $this->input->post('i_id_pegawai'),
            'nama_pegawai'   => $this->input->post('i_nama_pegawai'),
            'password'       => $this->input->post('i_password'),
            'hak_akses'      => $this->input->post('i_hak_akses'),
            'status_pegawai' => $this->input->post('i_status_pegawai')
        );
        
        $this->form_validation->set_rules('i_id_pegawai', 'No Induk', 'required|min_length[5]|max_length[18]|integer');
        $this->form_validation->set_rules('i_nama_pegawai', 'Nama Lengkap', 'required|min_length[6]|max_length[25]');
        $this->form_validation->set_rules('i_password', 'Password', 'required|min_length[8]|max_length[15]');
        $this->form_validation->set_rules('i_hak_akses', 'Jabatan', 'required');
        
        if($this->form_validation->run() == FALSE){
            $this->menu('Form_registrasi');
        }else{
            $this->Pegawai->edit($input);
            $this->menu('Manajemen_user');
        }
    }
    
    function valid_kelola_arsip() {
        
    }

    function valid_kelola_report() {
        
    }

    function log_in() {
        
    }

    function log_out() {
        
    }
    
}

?>
